package cn.jbolt.ec.coupon;

import cn.jbolt._admin.permission.CheckPermission;
import cn.jbolt._admin.permission.PermissionKey;
import cn.jbolt._admin.permission.UnCheck;
import cn.jbolt._admin.permission.UnCheckIfSystemAdmin;
import cn.jbolt.base.JBoltBaseController;
import cn.jbolt.common.bean.OptionBean;
import cn.jbolt.common.model.BecRetailerChargeBonus;
import cn.jbolt.common.model.BecRetailerCoupon;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;
import jodd.util.collection.JoddArrayList;

import java.util.ArrayList;
import java.util.List;


@CheckPermission(PermissionKey.COUPON_ADMIN)
public class EcRetailerCouponAuthController extends JBoltBaseController {

    @Inject
    RetailerCouponService retailerCouponService;

    @CheckPermission(PermissionKey.COUPON_INDEX)
    public void index(){
        keepPara();
        set("pageData",retailerCouponService.get_retailer_coupon_page(getPageNumber(),getPageSize(),getKeywords(),getInt("retailerId"),getLong("onTime")));
        render("index.html");
    }



    @CheckPermission(PermissionKey.COUPON_ADD)
    public void add(){
        render("add_from.html");
    }

    @CheckPermission({PermissionKey.COUPON_MODIFY})
    public void modify(){
        set("retailer_coupon",retailerCouponService.findById(getInt(0)));
        render("modify_from.html");
    }


    public void save(){
        renderJson(retailerCouponService.save(getModel(BecRetailerChargeBonus.class,"retailer_coupon"),get("charge_amount"),get("value"),getDate("expired")));
    }


    public void update(){
        renderJson(retailerCouponService.update(getModel(BecRetailerChargeBonus.class,"retailer_coupon"),get("charge_amount"),get("value"),getDate("expired")));
    }


    @CheckPermission(PermissionKey.COUPON_DELETE)
    public void delete(){
        renderJson(retailerCouponService.delete(getInt(0)));

    }


    /**
     * select 时间下拉数据源
     */
    public void get_retailer_coupon_time(){
        List<OptionBean> options=new ArrayList<OptionBean>();
        options.add(new OptionBean("近一天过期",1));
        options.add(new OptionBean("近三天过期",3));
        options.add(new OptionBean("近十天过期",10));
        options.add(new OptionBean("近一个月过期",31));
        options.add(new OptionBean("近三个月过期",93));
        renderJsonData(options);
    }



}
